<?php
/**
 *
 * @author james
 * @version 
 */
require_once 'Zend/View/Interface.php';

/**
 * UserCity helper
 *
 * @uses viewHelper Zend_View_Helper
 */
class Zend_View_Helper_UserCity {
	
	/**
	 * @var Zend_View_Interface 
	 */
	public $view;
	
	/**
	 * Get user city. 
	 */
	public function userCity() {
		$userCity = null;
		$userData = $this->view->loggedInUser();
		
        if (isset($userData)) {
            //user has logged In
            $user = new User();
            $user = $user->findById($userData->id);
            $userCity = User::getTopCity($user);  
        } else {
            //user hasn't logged In
            $cityId = SessionUtil::getProperty(Constant::KEY_CITY_ID);
            if (empty($cityId)) {
                $cityId = 1;
            }
            $userCity = City::getTopCity($cityId);
        }
        
        return $userCity; 
	}
	
	/**
	 * Sets the view field 
	 * @param $view Zend_View_Interface
	 */
	public function setView(Zend_View_Interface $view) {
		$this->view = $view;
	}
}

